using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class testCamera : MonoBehaviour
{
    //��һ�ӽ���
    public float m_speed;
    private Vector3 _rotation;
    private Vector3 _rotationEnd;
    private Vector3 moveRotation = Vector3.zero;
    public Transform _podTrans;
    public Rigidbody D;
    private bool parent_bool;
    public float rotation_Speed;//�ӽ���ת������

    private bool mouseDown_bool;//��갴��ʱ�Ƿ���ָ���ķ�Χ��
    private bool wrong_bool = true;//�Ƿ񲹲�

    public Collider collider;

    //internal bool �ӽ�_bool;
    internal static bool upDown_bool = true;//������λ
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(1) || Input.GetMouseButton(0))
        {
            //Debug.Log("aaa");

            //var mouseX = Input.GetAxis("Mouse X");
            //var mouseY = Input.GetAxis("Mouse Y");
            //_podTrans.DOKill(false);
            //wrong_bool = false;
            //Debug.Log(_podTrans.localEulerAngles.x);

            //���ÿ�ΰ���ʱ���н���

            _rotation.x = CheckAngle(transform.localEulerAngles.x);
            _rotation.y = CheckAngle(_podTrans.localEulerAngles.y);

            //_rotation.x = transform.localEulerAngles.x;
            //_rotation.y = _podTrans.localEulerAngles.y;
            //_rotation = _podTrans.eulerAngles.x >= 229.90?new Vector3(-30,_podTrans.eulerAngles.y,0) : _podTrans.eulerAngles;//ÿ����갴�½�����ת
            _rotation.y += 360 * Time.deltaTime * Input.GetAxis("Mouse X") * rotation_Speed;

            _rotation.x = Mathf.Clamp(_rotation.x - 360 * Time.deltaTime * Input.GetAxis("Mouse Y") * rotation_Speed, -30, 50);

            moveRotation.y = _rotation.y;
            _podTrans.localEulerAngles = moveRotation;
            _rotationEnd.x = _rotation.x;
            _rotationEnd.z = _rotation.z;
            transform.localEulerAngles = _rotationEnd;

        }
    }
    private void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.W) | Input.GetKey(KeyCode.UpArrow))
        {
            _podTrans.Translate(Vector3.forward * m_speed * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.S) | Input.GetKey(KeyCode.DownArrow))
        {
            _podTrans.Translate(Vector3.back * m_speed * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.A) | Input.GetKey(KeyCode.LeftArrow))
        {
            _podTrans.Translate(Vector3.left * m_speed * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.D) | Input.GetKey(KeyCode.RightArrow))
        {
            _podTrans.Translate(Vector3.right * m_speed * Time.deltaTime);
        }
        if (_podTrans.localPosition.y < 12f && Input.GetKey(KeyCode.E))//�޸�
        {
            _podTrans.Translate(Vector3.up * 10 * Time.deltaTime);
        }
        if ((_podTrans.localPosition.y > 1.3f && upDown_bool) && Input.GetKey(KeyCode.Q))//�޵�
        {
            _podTrans.Translate(Vector3.down * 10 * Time.deltaTime);
        }


        
    }

    public float CheckAngle(float value)
    {
        float angle = value - 180f;

        if (angle > 0)
            return angle - 180f;

        return angle + 180f;
    }
}
